<?php

namespace App\Repositories\Eloquent\Admin;

use App\Repositories\Eloquent\BaseModel;
use EasySwoole\ORM\AbstractModel;


class MemberModel extends AbstractModel
{
    use BaseModel;
    protected $tableName = 'k_user';
    protected $connectionName = 'wr';
    protected $autoTimeStamp = true;
    protected $createTime = 'add_time';
    protected $updateTime = 'update_time';



    public function getList(array $where = [],$pageNum = PAGE_SIZE){

        $field = ['a.*','b.name','b.channel','b.phone','b.head_url','b.is_vip','b.expiration_time','b.sex','b.last_login_time'];
        $datas = $this->create()->alias('a')->field($field)
            ->join('k_user_info as b','a.id = b.id_user','LEFT')
            ->where($where)
            ->order('a.id','desc')
            ->_page($pageNum);
        return $datas;
    }

    public function getItem(int $memberId = 0){
        $field = ['a.*','b.name','b.channel','b.phone','b.head_url','b.is_vip','b.expiration_time','b.sex','b.last_login_time'];
        $datas = $this->create()->alias('a')->field($field)
            ->join('k_user_info as b','a.id = b.id_user','LEFT')
            ->where(['b.id_user'=>$memberId,'a.status'=>1])
            ->order('a.id','desc')
            ->get();
        return $datas;
    }


}